#include <iostream>
#include <cmath>
#include <unordered_map>

bool is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(std::sqrt(num)); i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

void closest_prime_number(std::string word1, std::string word2, std::string word3) {
    std::unordered_map<std::string, int> numbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    int num = (numbers.count(word1) ? numbers[word1] : -1) * 100 +
              (numbers.count(word2) ? numbers[word2] : -1) * 10 +
              (numbers.count(word3) ? numbers[word3] : -1);
    
    if (num < 100 || num > 999) {
        std::cout << "Wrong input" << std::endl;
        return;
    }
    
    int lower = num;
    int upper = num;
    while (!is_prime(lower) && !is_prime(upper)) {
        lower--;
        upper++;
    }
    
    while (!is_prime(lower)) {
        lower--;
    }
    
    while (!is_prime(upper)) {
        upper++;
    }
    
    if (is_prime(lower)) {
        std::cout << lower << std::endl;
    } else {
        std::cout << upper << std::endl;
    }
}

int main() {
    std::string word1, word2, word3;
    std::cin >> word1 >> word2 >> word3;
    closest_prime_number(word1, word2, word3);
    return 0;
}

